package com.crm.controller;

import com.crm.dto.ContractDto;
import com.crm.dto.ContractQueryPagePramDto;
import com.crm.pojo.Contract;
import com.crm.result.PageResult;
import com.crm.result.ResponseResult;
import com.crm.result.Result;
import com.crm.service.ContractService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/contract")
@Api(tags = "合同管理相关接口")
public class ContractController {
    @Autowired
    private ContractService contractService;

    /**
     * 分页查询合同
     *
     * @param dto
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("分页查询")
    public Result queryPageContract(ContractQueryPagePramDto dto) {
        log.info("合同分页查询参数{}", dto);
        PageResult result = contractService.queryContractList(dto);
        return Result.commonSuccess(result);
    }

    /**
     * 根据合同id查询合同详情
     */
    @ApiOperation("根据id查询")
    @GetMapping("/{id}")
    public Result queryById(@PathVariable String id) {
        log.info("根据id{}查询合同详情", id);
        Contract result = contractService.queryById(id);
        return Result.success(result);
    }

    /**
     * 新增合同
     */
    @PostMapping
    @ApiOperation("新增")
    public Result addContract(@RequestBody ContractDto dto) {
        log.info("新增合同参数{}", dto);
        contractService.addContact(dto);
        return Result.success();
    }

    /**
     * 查询回显
     */
    @GetMapping("/detail/{id}")
    @ApiOperation("查询回显")
    public Result getById(@PathVariable String id) {
        log.info("根据id查询查询回显{}", id);
        Contract contract = contractService.getById(id);
        return Result.success(contract);
    }

    /**
     * 修改合同
     */
    @PutMapping
    public ResponseResult updateContract( @RequestBody ContractDto dto) {
        log.info("修改合同相关参数{}",dto);
        contractService.updateContract(dto);
        return ResponseResult.success();
    }


}
